import { ref } from 'vue';
const useCountDown = () => {
    const counter = ref(0)
    const interval = ref(null)
  
    const startCountDown = num => {
      counter.value = Number(num)
      clearCountDown()
      interval.value = setInterval(() => {
        if (counter.value === 0) {
          clearInterval(interval.value)
          interval.value = null
          return
        }
        counter.value--
      }, 1000)
    }
  
    const clearCountDown = () => {
      if (interval.value) {
        clearInterval(interval.value)
      }
    }
  
    return { counter, startCountDown, clearCountDown }
  }
  
  export { useCountDown }